import axios from 'axios'

export function fetch (url, parameObj = {}, method = 'POST') {
    return new Promise((resolve,reject) => {
        var postParameObj = {}
        var getParameObj = {}
        if (method.toUpperCase() === 'POST' || method.toUpperCase() === 'PUT') {
            postParameObj = parameObj
        } else {
            getParameObj = parameObj
        }
        let headers = {}
        if (parameObj.headers) {
            headers = parameObj.headers
        }
        // headers['X-Auth-Value'] = ''
        // headers['X-Emp-No'] = ''
        axios({
            method: method,
            url: url,
            data: postParameObj,
            params: getParameObj,
            headers: headers
        }).then((response) => {
            if (response.data.code === '200') {
                resolve(response.data)
            } else {
                reject(response.data)
            }
        }).catch((error) => {
            reject(error)
        })
    })
}


// axios.interceptors.request.use(
//     config => {
//         const token = getCookie('PORTALSSOCookie') || getCookie('ZTEDPGSSOCookie')
//         if(tokne){
//             config.headers['X-Auth-Value'] = encodeURIComponent(tokne)
//             config.headers['X-Emp-No'] = getCookie('PORTALSSOUser') || getCookie('ZTEDPGSSOUser')
//             config.headers['X-Lang-Id'] = getXLangId()
//         }
//         return config
//     },
//     err =>{
//         return Promise.reject(err)
//     }
// )
